package com.wanjian.sak;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;

import com.wanjian.sak.config.Config;
import com.wanjian.sak.layer.impl.MarginLayer;
import com.wanjian.sak.layer.impl.RelativeLayerView;

public class SAK {
    private static Scaffold sScaffold;

    private SAK() {
    }

    @TargetApi(Build.VERSION_CODES.M)
    public static void init(Application application) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Log.w("SAK", "暂不支持Android5.0以下设备");
            return;
        }

        boolean hasOverlay =Settings.canDrawOverlays(application) ;
        if (!hasOverlay) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            application.startActivity(intent);
            return;
        }

        if (sScaffold != null) {
            return;
        }

        sScaffold = new Scaffold();

        Config config = new Config.Build(application)
                .addLayer(MarginLayer.class, application.getDrawable(R.drawable.sak_margin_icon), "外边距" ,false)
                .addLayer(RelativeLayerView.class, application.getDrawable(R.drawable.sak_relative_distance_icon),"相对距离"  ,false)
                .build();
        sScaffold.start(application, config);
    }

}
